package cn.springBoot.controller;

import cn.springBoot.dto.*;
import cn.springBoot.util.DrawUtils;
import org.camunda.bpm.engine.*;
import org.camunda.bpm.engine.repository.Deployment;
import org.camunda.bpm.engine.repository.DeploymentQuery;
import org.camunda.bpm.engine.repository.ProcessDefinition;
import org.camunda.bpm.model.bpmn.Bpmn;
import org.camunda.bpm.model.bpmn.BpmnModelInstance;
import org.camunda.bpm.model.bpmn.instance.*;
import org.camunda.bpm.model.bpmn.instance.Process;
import org.camunda.bpm.model.bpmn.instance.UserTask;
import org.camunda.bpm.model.bpmn.instance.bpmndi.*;
import org.camunda.bpm.model.bpmn.instance.camunda.CamundaExecutionListener;
import org.camunda.bpm.model.bpmn.instance.camunda.CamundaFormData;
import org.camunda.bpm.model.bpmn.instance.camunda.CamundaFormField;
import org.camunda.bpm.model.bpmn.instance.dc.Bounds;
import org.camunda.bpm.model.bpmn.instance.di.Edge;
import org.camunda.bpm.model.bpmn.instance.di.Shape;
import org.camunda.bpm.model.bpmn.instance.di.Waypoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPathExpressionException;
import java.io.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ljx
 * @description:    流程定义
 * @class cn.springBoot.controller.CamundaController
 * @create date: 2021/9/15
 *
 *
 * 基本概念
 * ProcessEngine:整个流程引擎
 *
 * Multi-Tenancy：多个子公司之间的数据隔离
 *
 * 静态部分：
 *
 *   Process Definitions 流程定义，对应一个BPMN xml，内部映射为一个图结构
 *
 *   Keys and Versionskey是id，相同key多次提交是不同version
 *
 *   Suspend Process Definitions  暂时挂起，不允许执行
 *
 *   Process Instances 一次执行，有中断状态时，会存库，用户操作后状态往后走
 *
 *   Activity 一个活动（process的下一级），包括task和subprocess
 *
 *   Task 需要用户或系统操作的任务
 *
 * runtime动态部分：
 *
 *   Variables 输入输出的数据
 *
 *   Executions执行的路径（可能是并行的流程中的一个，也可能是子流程），可以表达一个变量的范围
 *
 *   token state ：整个执行的过程是token传递的过程
 *
 *   job具体调度的内容，execution的下一层，实际做的事情由jobHandler确定
 *
 * 核心服务
 *
 *   RepositoryService 存储流程定义
 *
 *   RuntimeService 管理运行实例，用事件来trigger流程往后走
 *
 *   TaskService人员需要处理的任务
 *
 *   IdentityService 身份验证
 *
 *   FormService 前端接口
 *
 *   HistoryService 历史数据的统处理
 *
 *   ManagementService 数据库操作
 *
 *   FilterService 筛选
 *
 *   ExternalTaskService 外部任务
 *
 */

@RestController()
@RequestMapping("/definition")
public class ProcessDefinitionController {

    // 存储流程定义
    @Autowired
    RepositoryService repositoryService;

    //人员需要处理的任务
    TaskService taskService;

    //前端接口
    FormService formService;
    //历史数据的统处理
    HistoryService historyService;
    //数据库操作
    ManagementService managementService;
    //筛选
    FilterService filterService;
    //外部任务
    ExternalTaskService externalTaskService;


   /**
    * @description: 添加流程定义
    * @param:name 流程定义名称
    * @Param: url  流程定义地址 eg： processes/audit.bpmn20.xml
    * @author: ljx
    * @create date: 2021/9/16
    * @version: V1.0
    * @return: boolean
    */


    @GetMapping(value ="/createDefinition" )
    public  boolean  createDefinition(String name ,String url) throws IOException {

      /* *//*   Deployment deployment = repositoryService.createDeployment()
             //.addClasspathResource("static/test.html")  //添加bpmn资源
                .addClasspathResource("diagram/ttt.bpmn")
                .name(name)
                .source("测试")
                .deploy();*//*

        //4.输出部署的一些信息
        System.out.println(deployment.getName());
        System.out.println(deployment.getId());*/
      // File f = new File("D:/localGit/springbootBeginner/src/main/resources/diagram/yyy.bpmn");
/*File f = new File("D:/localGit/springbootBeginner/src/main/resources/diagram/yyy.bpmn");
        File from = new File("D:/localGit/springbootBeginner/src/main/resources/static/forms/test.html");
*/
        File f = new File(url);
        InputStream inputStreambpmn=new FileInputStream(f);
      /*  InputStream inputStreamForm=new FileInputStream(from);*/
        Deployment deployment = repositoryService// 与流程定义和部署对象相关的sevices
                .createDeployment()// 创建一个部署对象
                .name(name)// 添加部署名称
                .addInputStream(name, inputStreambpmn)
            /*   .addInputStream("test.html",inputStreamForm)*/
                .deploy();// 完成部署
        System.out.println("部署ID：" + deployment.getId());
        System.out.println("部署名称" + deployment.getName());

        inputStreambpmn.close();
        return true;
    }

/*
      //根据流的形势部署
    public void addInputStream() {
        String resoueceName = "3.bpmn";

        InputStream inputStream = DeploymentTest.class.getClassLoader().getResourceAsStream("com.demo/ch8/diagram_1.bpmn");

        DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
        Deployment deployment = deploymentBuilder
                .name("请求流程")
                .source("本地测试")
                .tenantId("a")
                .addInputStream(resoueceName, inputStream)
                .deploy();

        System.out.println(deploymentBuilder);
        System.out.println(deployment);
    }


     //根据压缩流的形势部署
    public void addZipInputStream() {

        InputStream inputStream = DeploymentTest.class.getClassLoader().getResourceAsStream("com.demo/ch8/diagram_1.bpmn.zip");

        ZipInputStream zipInputStream = new ZipInputStream(inputStream);

        DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
        Deployment deployment = deploymentBuilder
                .name("请求流程")
                .source("本地测试")
                .tenantId("a")
                .addZipInputStream(zipInputStream)
                .deploy();

        System.out.println(deploymentBuilder);
        System.out.println(deployment);
    }


       //自定义模型方式部署
      public void createExecutableProcess() throws IOException {
        BpmnModelInstance bpmnModelInstance = Bpmn.createExecutableProcess("leave")
                .startEvent().name("开始节点")
                .userTask("申请人").camundaCandidateUsers("张三")
                .exclusiveGateway().name("排他网关").condition("小于三天", "${day<3}")
                .userTask().name("组长审批").camundaCandidateUsers("张三")
                .endEvent()

                .findLastGateway()
                .builder().condition("大于等于三天", "${day>=3}")
                .userTask().name("组长审批").camundaCandidateUsers("李四")
                .userTask().name("项目经理审批").camundaCandidateUsers("王五")
                .endEvent()

                .done();

        repositoryService.createDeployment()
                .addModelInstance("customer.bpmn", bpmnModelInstance)
                .deploy();

    }


      //获取模型 编辑 再部署
     public void getBpmnModelInstance() throws IOException {
        String processDefinitionId = "leave:8:4303";

        BpmnModelInstance bpmnModelInstance = repositoryService.getBpmnModelInstance(processDefinitionId);
        Collection<UserTask> modelElementsByType = bpmnModelInstance.getModelElementsByType(UserTask.class);

        System.out.println("###########" + modelElementsByType);


        DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
        deploymentBuilder
                .addModelInstance("customer.bpmn", bpmnModelInstance).deploy();
    }

 
*/


   /**
    * @description: 获取流程定义列表
    * @param:
    * @author: ljx
    * @create date: 2021/9/16
    * @version: V1.0
    * @return: java.util.List<org.camunda.bpm.engine.repository.ProcessDefinition>
    */

   @GetMapping("/getDefinitionList")
   public List<ProcessDefinition> getDefinitionList(){

       DeploymentQuery deploymentQuery = repositoryService.createDeploymentQuery();

       List<Deployment> list = deploymentQuery.list();
       for (Deployment deployment : list) {
           System.out.println("sss"+deployment.toString());
       }
       System.out.println("---------------------------------------------------------------------");
       List<ProcessDefinition> processDefinitionList = repositoryService.createProcessDefinitionQuery()
                   .latestVersion()//最新结果
                   //添加查询条件
                   //.processDefinitionName("流程定义的name")
                   //.processDefinitionId("流程定义的id")
                   //.processDefinitionKey("流程定义的key")
                   //排序
                   .orderByProcessDefinitionVersion().asc()
                   //查询结果
                   //.count() //返回结果集数量
                   //.listPage(firstResult,  maxResults)//分页查询
                   //.singleResult() //唯一结果
                   .list();//总的结果集数量
           for(ProcessDefinition processDefinition:processDefinitionList){
               System.out.println("id:" +processDefinition.getId());
               System.out.println("name:" +processDefinition.getName());
               System.out.println("key:" +processDefinition.getKey());
               System.out.println("version:" +processDefinition.getVersion());
               System.out.println("resourceName:" +processDefinition.getDiagramResourceName());
           }

       return null;

   }

    /**
     * @description:  删除流程定义
     * @param:deploymentId
     * @author: ljx
     * @create date: 2021/9/16
     * @version: V1.0
     * @return: boolean
     */

   @GetMapping("/delDefinition")
   public boolean delDefinition(String deploymentId){

       repositoryService.deleteDeployment(deploymentId);

        return  true;
   }

/*    @GetMapping("/auto")
    public void createExecutableProcess() throws IOException {
        BpmnModelInstance bpmnModelInstance = Bpmn.createExecutableProcess("leave")
                .startEvent().name("开始节点")
                .userTask("申请人").camundaCandidateUsers("张三")
                .exclusiveGateway().name("排他网关").condition("小于三天", "${day<3}")
                .userTask().name("组长审批").camundaCandidateUsers("张三")
                .endEvent()

                .findLastGateway()
                .builder().condition("大于等于三天", "${day>=3}")
                .userTask().name("组长审批").camundaCandidateUsers("李四")
                .userTask().name("项目经理审批").camundaCandidateUsers("王五")
                .endEvent()

                .done();

        repositoryService.createDeployment()
                .addModelInstance("customer.bpmn", bpmnModelInstance)
                .deploy();

    }*/

    @GetMapping("/auto")
    public void createExecutableProcess() throws IOException {
        BpmnModelInstance bpmnModelInstance = Bpmn.createExecutableProcess("testExecutableProcess")
                .startEvent().name("开始节点").id("start")

                .endEvent().id("end")

                .done();
        StartEvent startEvent = bpmnModelInstance.getModelElementById("start");
        repositoryService.createDeployment()
                .addModelInstance("customer.bpmn", bpmnModelInstance)
                .deploy();

    }
    @PostMapping("/createExecutableProcessByJson")
    public  void createExecutableProcessByJson(@RequestBody ProcessDfinitionDto processDfinitionDto) throws ParserConfigurationException, SAXException, XPathExpressionException, IOException {
        //保存吗? processDfinitionDto


        // 1、创建模型
        BpmnModelInstance modelInstance = Bpmn.createEmptyModel();

        //2、创建BPMN定义元素，设置目标名称空间，并将其添加到新创建的模型实例中
        Definitions definitions = modelInstance.newInstance(Definitions.class);
        definitions.setTargetNamespace("http://bpmn.io/schema/bpmn");
        modelInstance.setDefinitions(definitions);

        // create the process
        // ①、创建BPMN实例；
        Process process = DrawUtils.createElement(definitions, processDfinitionDto.getId(), Process.class);

        process.setName(processDfinitionDto.getName());
        //设置可执行实例
        process.setExecutable(true);

        // create elements  创建节点

      if (!processDfinitionDto.getTaskNodeList().isEmpty()){

          for (TaskNode TaskNode :processDfinitionDto.getTaskNodeList()) {

              switch (TaskNode.getNodeType()) {

                  case ("startEvent"):

                      //开始节点
                      StartEvent startEvent = DrawUtils.createElement(process, TaskNode.getId(), StartEvent.class);
                      startEvent.setName(TaskNode.getName());

                      //监听设置
                      if (TaskNode.getTaskListenerList()!=null){

                          for (TaskListener listener: TaskNode.getTaskListenerList()) {
                             if( listener.getListenerType().equals("camundaExecutionListener")){
                                 // 执行监听
                                 CamundaExecutionListener camundaExecutionListenerStar = modelInstance.newInstance(CamundaExecutionListener.class);

                                 camundaExecutionListenerStar.setCamundaEvent(listener.getEnvetType());
                                 //camundaExecutionListenerStar.setCamundaClass(listener.getDelegateExpression());
                                 camundaExecutionListenerStar.setCamundaDelegateExpression(listener.getDelegateExpression());
                                 startEvent.builder()
                                         .addExtensionElement(camundaExecutionListenerStar);
                             }else  if( listener.getListenerType().equals("taskListener")){
                                 //任务监听 待完善

                             }
                          }
                      }

                      break;
                  case ("endEvent"):
                      EndEvent endEvent = DrawUtils.createElement(process, TaskNode.getId(), EndEvent.class);
                      endEvent.setName(TaskNode.getName());
                      //监听设置
                      if (TaskNode.getTaskListenerList()!=null){

                          for (TaskListener listener: TaskNode.getTaskListenerList()) {
                              if( listener.getListenerType().equals("camundaExecutionListener")){
                                  // 执行监听
                                  CamundaExecutionListener camundaExecutionListenerStar = modelInstance.newInstance(CamundaExecutionListener.class);
                                  camundaExecutionListenerStar.setCamundaEvent(listener.getEnvetType());
                                  camundaExecutionListenerStar.setCamundaDelegateExpression(listener.getDelegateExpression());
                                  endEvent.builder()
                                          .addExtensionElement(camundaExecutionListenerStar);
                              }else  if( listener.getListenerType().equals("taskListener")){
                                  //任务监听 待完善

                              }
                          }
                      }

                      break;
                  case ("userTask"):

                      //用户任务
                      UserTask userTask=DrawUtils.createElement(process, TaskNode.getId(), UserTask.class);
                      userTask.setName(TaskNode.getName());

                      //监听设置
                      if (TaskNode.getTaskListenerList()!=null){

                          for (TaskListener listener: TaskNode.getTaskListenerList()) {
                              if( listener.getListenerType().equals("camundaExecutionListener")){
                                  // 执行监听
                                  CamundaExecutionListener camundaExecutionListenerStar = modelInstance.newInstance(CamundaExecutionListener.class);
                                  camundaExecutionListenerStar.setCamundaEvent(listener.getEnvetType());
                                  camundaExecutionListenerStar.setCamundaDelegateExpression(listener.getDelegateExpression());
                                  userTask.builder()
                                          .addExtensionElement(camundaExecutionListenerStar);
                              }else  if( listener.getListenerType().equals("taskListener")){
                                  //任务监听 待完善

                              }
                          }
                      }

                      //details设置
                      if (TaskNode.getTaskDetails()!=null){

                          if (TaskNode.getTaskDetails().getAssignee()!=null){
                              //指定处理人
                              userTask.setCamundaAssignee(TaskNode.getTaskDetails().getAssignee());
                          }

                          if (TaskNode.getTaskDetails().getUsers()!=null){

                              //指定多人处理
                              userTask.setCamundaCandidateUsers(TaskNode.getTaskDetails().getUsers());
                          }

                          if (TaskNode.getTaskDetails().getGroup()!=null){

                              //指定组处理
                              userTask.setCamundaCandidateGroups(TaskNode.getTaskDetails().getGroup());
                          }
                            //会签
                          if (TaskNode.getTaskDetails().getCollection()!=null){

                              MultiInstanceLoopCharacteristics  multiInstanceLoopCharacteristics = modelInstance.newInstance(MultiInstanceLoopCharacteristics.class);

                              multiInstanceLoopCharacteristics.setCamundaCollection(TaskNode.getTaskDetails().getCollection());
                              //加上true就是并行 不加就是串行
                              if (TaskNode.getTaskDetails().isSequential()){

                                  multiInstanceLoopCharacteristics.setSequential(true);
                              }

                              multiInstanceLoopCharacteristics.setCamundaElementVariable(TaskNode.getTaskDetails().getElementVariable());

                              userTask.setLoopCharacteristics(multiInstanceLoopCharacteristics);
                          }
                      }

                      //添加外置表单
                      if(TaskNode.getFormKey()!=null){

                          userTask.setCamundaFormKey(TaskNode.getFormKey());

                      }
                      //添加动态表单
                      if (TaskNode.getCustomform()!=null){


                          CamundaFormData formData = modelInstance.newInstance(CamundaFormData.class);

                          for (TaskForm taskForm: TaskNode.getCustomform()) {
                              CamundaFormField formField=modelInstance.newInstance(CamundaFormField.class);

                              formField.setCamundaId(taskForm.getId());
                              formField.setCamundaLabel(taskForm.getLabel());
                              formField.setCamundaType(taskForm.getType());

                              formData.addChildElement(formField);
                          }
                          //将表单添加到用户任务
                          userTask.builder().addExtensionElement(formData);
                      }

                      break;
                  case ("serviceTask"):


                      //系统任务
                      ServiceTask  serviceTask= DrawUtils.createElement(process, TaskNode.getId(), ServiceTask.class);
                      serviceTask.setName(TaskNode.getName());

                      //监听设置
                      if (TaskNode.getTaskListenerList()!=null){

                          for (TaskListener listener: TaskNode.getTaskListenerList()) {
                              if( listener.getListenerType().equals("camundaExecutionListener")){
                                  // 执行监听
                                  CamundaExecutionListener camundaExecutionListenerStar = modelInstance.newInstance(CamundaExecutionListener.class);
                                  camundaExecutionListenerStar.setCamundaEvent(listener.getEnvetType());
                                /*  camundaExecutionListenerStar.setCamundaClass(listener.getJavaClass());*/
                                  camundaExecutionListenerStar.setCamundaDelegateExpression(listener.getDelegateExpression());
                                  serviceTask.builder()
                                          .addExtensionElement(camundaExecutionListenerStar);
                              }else  if( listener.getListenerType().equals("taskListener")){
                                  //任务监听 待完善

                              }
                          }
                      }

                      //details设置
                      if (TaskNode.getTaskDetails()!=null){


                          //implementation 实施
                          if (TaskNode.getTaskDetails().getImplementation()!=null){

                              if( TaskNode.getTaskDetails().getImplementation().get("delegateExpression")!=null){

                                  serviceTask.setCamundaDelegateExpression((String) TaskNode.getTaskDetails().getImplementation().get("delegateExpression"));

                              }else if ( TaskNode.getTaskDetails().getImplementation().get("javaClass")!=null){

                                  serviceTask.setCamundaClass((String) TaskNode.getTaskDetails().getImplementation().get("javaClass"));
                              }

                          }
                          //会签
                          if (TaskNode.getTaskDetails().getCollection()!=null){

                              MultiInstanceLoopCharacteristics  multiInstanceLoopCharacteristics = modelInstance.newInstance(MultiInstanceLoopCharacteristics.class);

                              multiInstanceLoopCharacteristics.setCamundaCollection(TaskNode.getTaskDetails().getCollection());
                              //加上true就是并行 不加就是串行
                              if (TaskNode.getTaskDetails().isSequential()){

                                  multiInstanceLoopCharacteristics.setSequential(true);
                              }

                              multiInstanceLoopCharacteristics.setCamundaElementVariable(TaskNode.getTaskDetails().getElementVariable());

                              serviceTask.setLoopCharacteristics(multiInstanceLoopCharacteristics);
                          }
                      }


                      //添加动态表单
                      if (TaskNode.getCustomform()!=null){


                          CamundaFormData formData = modelInstance.newInstance(CamundaFormData.class);

                          for (TaskForm taskForm: TaskNode.getCustomform()) {
                              CamundaFormField formField=modelInstance.newInstance(CamundaFormField.class);

                              formField.setCamundaId(taskForm.getId());
                              formField.setCamundaLabel(taskForm.getLabel());
                              formField.setCamundaType(taskForm.getType());
                              formData.addChildElement(formField);
                          }
                          //将表单添加到用户任务
                          serviceTask.builder().addExtensionElement(formData);
                      }

                      break;
                  case ("exclusiveGateway"):


                      //创建排他网关 是否发送邀请函
                      ExclusiveGateway exclusiveGateway =DrawUtils.createElement(process, TaskNode.getId(), ExclusiveGateway.class);
                      exclusiveGateway.setName(TaskNode.getName());

                      //监听设置
                      if (TaskNode.getTaskListenerList()!=null){

                          for (TaskListener listener: TaskNode.getTaskListenerList()) {
                              if( listener.getListenerType().equals("camundaExecutionListener")){
                                  // 执行监听
                                  CamundaExecutionListener camundaExecutionListenerStar = modelInstance.newInstance(CamundaExecutionListener.class);
                                  camundaExecutionListenerStar.setCamundaEvent(listener.getEnvetType());
                                  /*camundaExecutionListenerStar.setCamundaClass(listener.getJavaClass());*/
                                  camundaExecutionListenerStar.setCamundaDelegateExpression(listener.getDelegateExpression());
                                  exclusiveGateway.builder()
                                          .addExtensionElement(camundaExecutionListenerStar);
                              }else  if( listener.getListenerType().equals("taskListener")){
                                  //任务监听 待完善

                              }
                          }
                      }

                      break;
                   case ("eventBasedGateway"):

                       break;

              }

          }
      }
        // 创建连线
        if (processDfinitionDto.getTaskSequenceFlowList()!=null){

            for (TaskSequenceFlow taskSequenceFlow: processDfinitionDto.getTaskSequenceFlowList()) {

                DrawUtils.createSequenceFlow(process,modelInstance,taskSequenceFlow);
            }

        }

        //创建画图
       // DrawUtils.diagram(modelInstance,process,definitions);


      //  BPMNDiagram

           // BPMNPlane

               //BPMNEdge  线
                  //waypoint
               //BPMNShape 图形    bpmnElement //关联节点
                  //Bounds

        BpmnDiagram bpmnDiagram = modelInstance.newInstance(BpmnDiagram.class);


        BpmnPlane plane = modelInstance.newInstance(BpmnPlane.class);


        //遍历 edge  
        

        for (EdgeDto e: processDfinitionDto.getDiagramDto().getPlane().getEdgeList()) {

            BpmnEdge edge=modelInstance.newInstance(BpmnEdge.class);

            for (WaypointDto waypointDto :e.getWaypointList()) {

                Waypoint waypoint=modelInstance.newInstance(Waypoint.class);

                waypoint.setX(waypointDto.getX());
                waypoint.setY(waypointDto.getY());
                edge.getWaypoints().add(waypoint);
            }
            if (e.getLabelDto()!=null){

                BpmnLabel bpmnLabel=modelInstance.newInstance(BpmnLabel.class);
                Bounds bounds=modelInstance.newInstance(Bounds.class);
                bounds.setY(e.getLabelDto().getBoundsDto().getY());
                bounds.setX(e.getLabelDto().getBoundsDto().getX());
                bounds.setWidth(e.getLabelDto().getBoundsDto().getWidth());
                bounds.setHeight(e.getLabelDto().getBoundsDto().getHeight());
                bpmnLabel.setBounds(bounds);
                edge.setBpmnLabel(bpmnLabel);

            }
            edge.setAttributeValue("bpmnElement",e.getBpmnElement());
            plane.addChildElement(edge);
        }


        for (ShapeDto shapeDto:processDfinitionDto.getDiagramDto().getPlane().getShapeList()) {

            BpmnShape shape =modelInstance.newInstance(BpmnShape.class);
            Bounds bounds =modelInstance.newInstance(Bounds.class);

            bounds.setHeight(shapeDto.getBounds().getHeight());
            bounds.setWidth(shapeDto.getBounds().getWidth());
            bounds.setX(shapeDto.getBounds().getX());
            bounds.setY(shapeDto.getBounds().getY());
            shape.setBounds(bounds);

            if (shapeDto.getLabelDto()!=null){

                BpmnLabel bpmnLabel=modelInstance.newInstance(BpmnLabel.class);
                Bounds childBounds=modelInstance.newInstance(Bounds.class);
                childBounds.setY(shapeDto.getLabelDto().getBoundsDto().getY());
                childBounds.setX(shapeDto.getLabelDto().getBoundsDto().getX());
                childBounds.setWidth(shapeDto.getLabelDto().getBoundsDto().getWidth());
                childBounds.setHeight(shapeDto.getLabelDto().getBoundsDto().getHeight());
                bpmnLabel.setBounds(childBounds);
                shape.setBpmnLabel(bpmnLabel);

            }
            shape.setAttributeValue("bpmnElement",shapeDto.getBpmnElement());
            plane.addChildElement(shape);
        }

        // process

        plane.setBpmnElement(process);
        bpmnDiagram.setBpmnPlane(plane);

        definitions.addChildElement(bpmnDiagram);



        //验证
        Bpmn.validateModel(modelInstance);
        //输出
        Bpmn.writeModelToFile(new File("D:\\"+"createExecutableProcessByJson"+".bpmn"), modelInstance);



    }



}
